#ifndef DB_SCHEMA_H
#define DB_SCHEMA_H

#include "common.h"

// 数据库表结构定义
typedef struct {
    char *key;
    char *value;
    char *type;
    char *description;
    time_t created_at;
    time_t updated_at;
} db_config_item_t;

typedef struct {
    char *key;
    json_t *value;
    time_t timestamp;
    time_t created_at;
    time_t updated_at;
} db_datapool_item_t;

typedef struct {
    int id;
    event_type_t type;
    char *source;
    char *description;
    json_t *data;
    time_t created_at;
} db_event_log_t;

typedef struct {
    char *component;
    char *status;
    json_t *details;
    time_t updated_at;
} db_system_status_t;

// 数据库初始化
int db_schema_init(sqlite3 *db);
int db_schema_create_tables(sqlite3 *db);
int db_schema_create_indexes(sqlite3 *db);

// 数据转换函数
db_config_item_t *db_config_item_create(const char *key, const char *value,
                                        const char *type, const char *description);
void db_config_item_free(db_config_item_t *item);

db_datapool_item_t *db_datapool_item_create(const char *key, json_t *value);
void db_datapool_item_free(db_datapool_item_t *item);

#endif
